knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
library(tidyverse)
library(here)
library(terra)
library(sf)
library(tmap)
In this task, we visually explore the location of 2008 oil spill incidents throughout the state of California. First, an interactive map with locations of every 2008 oil spill is generated for the user to explore individual incidents. Next, a choropleth map is created to visualize which CA counties had the highest number of inland oil spill incidents. Data used in this analysis comes from the Office of Spill Prevention and Response (OSPR) online database. An “incident” is defined by the OSPR as “a discharge or threatened discharge of petroleum or other deleterious material into the waters of the state.”
Source: Lampinen, Mark (2020). Oil Spill Incident Tracking [ds394]. California Department of Fish and Game, Office of Spill Prevention and Response. https://gis.data.ca.gov/datasets/CDFW::oil-spill-incident-tracking-ds394-1/about
A floating barrier known as booms is set up to try to stop further incursion into the Wetlands Talbert Marsh after an oil spill in Huntington Beach, CA, October 2021. Credit: Ringo H.W. Chiu/AP
### Read in and wrangle data!
### read in CA counties
ca_counties_sf <- read_sf(here('task1/ca_counties/CA_Counties_TIGER2016.shp')) %>%
janitor::clean_names() %>%
## only keep name and geom
select(name)
### read in the oil data
oil_spill <- read_csv(here('task1/Oil_Spill_Incident_Tracking_[ds394].csv')) %>%
janitor::clean_names()
### change oil spill data to sf so we can plot points
oil_spill_sf <- st_as_sf(oil_spill, coords = c('x','y'),
## set CRS to counties
crs = st_crs(ca_counties_sf))
### double-check CRS matches
# st_crs(ca_counties_sf) == st_crs(oil_spill_sf)
# [1] TRUE
### change oil spill data to sf
oil_spill_sf <- st_as_sf(oil_spill, coords = c('x','y'),
## set CRS to counties
crs = st_crs(ca_counties_sf))
### double-check CRS matches
# st_crs(ca_counties_sf) == st_crs(oil_spill_sf)
# [1] TRUE
### plot oil spill events in CA counties
tmap_mode('view')
tm_shape(ca_counties_sf) +
tm_borders(lwd = 1, col = 'gray40') +
tm_shape(oil_spill_sf) +
tm_dots(col = 'darkorchid4', alpha = 0.5)